from robyn import jsonify, Response
from typing import Optional, Any
import orjson

from common.response.http_response import CustomBaseResponse
from common.response.response_code import StandardResponseCode

class JsonResult():
        
    @staticmethod
    def success(msg: Optional[str] = None, data: Optional[Any] = None,
        code: int = StandardResponseCode.HTTP_200, **kwargs):
        
        return Response(
            status_code=code,
            description=jsonify(CustomBaseResponse(code=code, msg=msg, data=data, **kwargs)),
            headers={"Content-Type": "application/json; charset=utf-8"}
        )
    
    @staticmethod
    def fail(msg: Optional[str] = None, data: Optional[Any] = None,
        code: int = StandardResponseCode.HTTP_500, **kwargs):
        return Response(
            status_code=code,
            description=jsonify(CustomBaseResponse(code=code, msg=msg, data=data, **kwargs)),
            headers={"Content-Type": "application/json; charset=utf-8"}
        )